import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login'
const routes = [
  {
    path:"/",redirect:"/login"
  },

  {
    path: "/login",
    // name: 'Login',
    component: Login
  },

  {
    path: "/register",
    component: () => import('../views/register')
  },

  {
    path:"/home",
    component:() => import('../views/Home'),
    meta:{
      loginRequest:true
    }
  },

  {
    path: "/ball",
    component: () =>import('../components/ball')
  },

  {
    path: "/snake",
    component: () => import('../components/snake')
  },

  {
    path: "/test",
    component: () => import('../components/test')
  },

  {
    path:"/flybird",
    component: () => import('../components/flybird')
  },
  {
    path: "/Planewar",
    component: ()=> import('../components/Planewar')
  },
  {
    path: "/Parkour",
    component: ()=>import('../components/Parkour')
  },

]


const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// router.beforeEach((to, from, next) => {
//   // 检查上面配置的 每个页面配置的 meta 信息 是否为需要登录
//   if (to.meta.loginRequest) {
//     if(localStorage.getItem('user')){
//       next()
//     }
//     else{
//       next({
//         path:'/login',
//         query:{
//           redirect:to.fullPath
//         }
//       })
//     }
//   }
//   else{
//     next()
//   }
// })

export default router
